package com.swust.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.swust.common.log.annotation.Log;
import com.swust.common.log.enums.BusinessType;
import com.swust.common.security.annotation.RequiresPermissions;
import com.swust.course.domain.CourseTech;
import com.swust.course.service.ICourseTechService;
import com.swust.common.core.web.controller.BaseController;
import com.swust.common.core.web.domain.AjaxResult;
import com.swust.common.core.utils.poi.ExcelUtil;
import com.swust.common.core.web.page.TableDataInfo;

/**
 * 授课Controller
 * 
 * @author LiuShuai
 * @date 2024-04-05
 */
@RestController
@RequestMapping("/courseTech")
public class CourseTechController extends BaseController
{
    @Autowired
    private ICourseTechService courseTechService;

    /**
     * 查询授课列表
     */
    @RequiresPermissions("course:courseTech:list")
    @GetMapping("/list")
    public TableDataInfo list(CourseTech courseTech)
    {
        startPage();
        List<CourseTech> list = courseTechService.selectCourseTechList(courseTech);
        return getDataTable(list);
    }

    /**
     * 导出授课列表
     */
    @RequiresPermissions("course:courseTech:export")
    @Log(title = "授课", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseTech courseTech)
    {
        List<CourseTech> list = courseTechService.selectCourseTechList(courseTech);
        ExcelUtil<CourseTech> util = new ExcelUtil<CourseTech>(CourseTech.class);
        util.exportExcel(response, list, "授课数据");
    }

    /**
     * 获取授课详细信息
     */
    @RequiresPermissions("course:courseTech:query")
    @GetMapping(value = "/{createBy}")
    public AjaxResult getInfo(@PathVariable("createBy") String createBy)
    {
        return success(courseTechService.selectCourseTechByCreateBy(createBy));
    }

    /**
     * 新增授课
     */
    @RequiresPermissions("course:courseTech:add")
    @Log(title = "授课", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseTech courseTech)
    {
        return toAjax(courseTechService.insertCourseTech(courseTech));
    }

    /**
     * 修改授课
     */
    @RequiresPermissions("course:courseTech:edit")
    @Log(title = "授课", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseTech courseTech)
    {
        return toAjax(courseTechService.updateCourseTech(courseTech));
    }

    /**
     * 删除授课
     */
    @RequiresPermissions("course:courseTech:remove")
    @Log(title = "授课", businessType = BusinessType.DELETE)
	@DeleteMapping("/{createBys}")
    public AjaxResult remove(@PathVariable String[] createBys)
    {
        return toAjax(courseTechService.deleteCourseTechByCreateBys(createBys));
    }
}
